package com.liugl.recyclerviewtest

import adapters.FruitAdapter
import adapters.LayoutType
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import kotlinx.android.synthetic.main.activity_simple_recycler.*
import utils.DataUtil

class AllRecycler : AppCompatActivity() {

    companion object {
        fun actionStart(context: Context, type: LayoutType) {
            val intent = Intent(context, AllRecycler::class.java)
            intent.putExtra("type", type)
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_simple_recycler)

        val type = intent.getSerializableExtra("type") as LayoutType

        val layoutManager: RecyclerView.LayoutManager

        when (type) {
            LayoutType.SIMPLE -> {
                layoutManager = LinearLayoutManager(this)
            }
            LayoutType.HORIZONTAL -> {
                layoutManager = LinearLayoutManager(this)
                layoutManager.orientation = LinearLayoutManager.HORIZONTAL
            }
            LayoutType.GRID -> {
                layoutManager = GridLayoutManager(this, 3)
            }
            LayoutType.WATERFALL -> {
                layoutManager = StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL)
            }
        }

        sRecycle.layoutManager = layoutManager

        val adapter = FruitAdapter(DataUtil.getFruitList(type == LayoutType.WATERFALL), type)
        sRecycle.adapter = adapter
    }

}